cd "/Users/cason/Dropbox/Research/Emiss_Trade_price_controls/data/"

use Subjects_11sessions.dta

** Drop practice period **
drop if Period<1

** Identify the required abatement reduction from investment depending on firm type **
gen invAbateRed = 13
replace invAbateRed = 12 if Subject == 2
replace invAbateRed = 10 if Subject == 3
replace invAbateRed = 8 if Subject == 4
replace invAbateRed = 7 if Subject == 5
replace invAbateRed = 5 if Subject == 6
replace invAbateRed = 3 if Subject == 7
replace invAbateRed = 2 if Subject == 8

** How much are abatement amounts saved by actual investment? **
gen S_invAbateRed = invAbateRed*Invest

** Abatement undertaken **
gen abatement = max(0, ASAQ-Purchased+Sold)

** Emissions are the unregulated amount, adjusted for the investment and shock, and abatement **
gen emissions = ASAQ + 23 - abatement

collapse (mean) meanInvest=Invest (sum) totEmissions=emissions totalInvest=Invest totalCost=PC savedAbate=S_invAbateRed (mean) emissShock=S, by( pri_control sess_num Period)

sum totEmissions, detail
by pri_control, sort : summarize totEmissions
by pri_control, sort : summarize totEmissions if Period>5
by pri_control, sort : tabstat totEmissions, statistics( mean semean ) by(Period)

** Adjust cost to include investment cost **
gen AggtotCost = totalCost + (200*totalInvest)

sum AggtotCost, detail
by pri_control, sort : summarize AggtotCost
by pri_control, sort : summarize AggtotCost if Period>5
by pri_control, sort : tabstat AggtotCost, statistics( mean semean ) by(Period)
